package com.cyrus.vueboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyrus.vueboot.mapper.auth.AdminMapper;
import com.cyrus.vueboot.pojo.auth.Admin;
import com.cyrus.vueboot.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/13
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public IPage selectAll(Integer page,Integer size,String key) {
        Page<Admin> adminPage = new Page<>(page,size);
        IPage<Admin> result = adminMapper.selectPage(adminPage,
                new QueryWrapper<Admin>().like("username",key).eq("isShow",1));
        return result;
    }

    @Override
    public void deleteAdmins(Long id) {
        update(new UpdateWrapper<Admin>().lambda().set(Admin::getIsShow, 0).set(Admin::getStatus,0).eq(Admin::getId, id));
    }

}
